var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
/*

认证会员

*/


function searchLists() {
    $.ajax({
        /*root.member.listUpgradeAudit*/
        url: root.member.listUpgradeAudit,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "page_num":1,
            "page_size":20,
            "login_account":$("#login_account").val(),
            "mobile_phone":$("#mobile_phone").val(),
            "register_time_begin":$("#register_time").val(),
            "register_time_end":$("#lastregister_time").val(),
            "create_time_begin":$("#create_time").val(),
            "create_time_end":$("#lastcreate_time").val(),
            "register_platform":$("#register_platform").val(),
            "company_name":$("#company_name").val(),
            "business_man":$("#business_man").val(),
            "business_phone":$("#business_phone").val(),
            "exam_status":$("#exam_status").val(),
            "business_type":$("#business_type").val(),
            "apply_type":$("#apply_type").val(),
            "organizationIds": sessionStorage.getItem("companya")
        }),
        success: function (data) {
            sessionStorage.setItem("examstatus",'')
            // couponlist1(data.result);
            couponlist1(data.data.result);
            console.log(data.data.result)
            $('.M-box3').pagination({
                pageCount: data.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    console.log(api)
                    $.ajax({
                        /*root.member.listUpgradeAudit*/
                        url: root.member.listUpgradeAudit,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            page_num:api.getCurrent(),
                            page_size:20,
                            "login_account":$("#login_account").val(),
                            "mobile_phone":$("#mobile_phone").val(),
                            "register_time_begin":$("#register_time").val(),
                            "register_time_end":$("#lastregister_time").val(),
                            "create_time_begin":$("#create_time").val(),
                            "create_time_end":$("#lastcreate_time").val(),
                            "register_platform":$("#register_platform").val(),
                            "company_name":$("#company_name").val(),
                            "business_man":$("#business_man").val(),
                            "business_phone":$("#business_phone").val(),
                            "exam_status":$("#exam_status").val(),
                            "business_type":$("#business_type").val(),
                            "apply_type":$("#apply_type").val(),
                            "organizationIds": sessionStorage.getItem("companya")
                        }),
                        success: function (result) {
                            console.log(result)
                            couponlist1(result.data.result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

// var j = 0;
function couponlist1(data, index){
    console.log(data)
    // var j = 0;
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    var datashu="";

    if(data !=null && data != ''){
        datashu =data[0].serial_number;
    }

    $.each(data, function (i, field) {
        var datashus = datashu++
        var rowData = new Array();
        rowData.push(field.member_id);
        rowData.push(field.login_account);
        rowData.push(field.mobile_phone);
        rowData.push(field.register_platform);
        rowData.push(field.register_time);
        rowData.push(field.create_time);
        rowData.push(field.company_name);
        rowData.push(field.business_man);
        rowData.push(field.business_phone);
        rowData.push(field.business_type);
        rowData.push(field.exam_status);
        rowData.push(datashus);
        rowData.push(field.id);
        rowData.push(field.apply_type);
        dataSource.push(rowData);

    });

    initDataTable(dataSource);

    function initDataTable(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[11]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[4];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets":4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[5];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets":5
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if(row[3]==10){
                            val='PC端'
                        }
                        else if(row[3]==20){
                            val='Andriod端'
                        }
                        else if(row[3]==30){
                            val='IOS端'
                        }
                        else if(row[3]==40){
                            val='H5端'
                        }else if(row[3]==50){
                            val='云采后台'
                        }else if(row[3]==60){
                            val='小程序端'
                        }
                        return val;
                    },
                    "targets":3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if(row[9]==10){
                            val='工程'
                        }
                        else if(row[9]==20){
                            val='工矿'
                        }
                        else if(row[9]==30){
                            val='商店'
                        }
                        else if(row[9]==40){
                            val='外贸'
                        }
                        else if(row[9]==50){
                            val='物业'
                        }
                        else if(row[9]==60){
                            val='其它'
                        }
                        return val;
                    },
                    "targets":9
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if(row[13]==10){
                            val='升级认证'
                        }
                        else if(row[13]==20){
                            val='注册认证'
                        }

                        return val;
                    },
                    "targets":10
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if(row[10]==10){
                            val='待审核'
                        }
                        else if(row[10]==20){
                            val='审核通过'
                        }
                        else if(row[10]==30){
                            val='审核失败'
                        }

                        return val;
                    },
                    "targets":11
                },

                {
                    "render": function (data, type, row, meta) {
                        var val='';
                        if(row[10]==10){
                            val = '<a class="powerButton 174"><span class="list"  onclick="detail(\'会员\',\'reviewFailure.html\',\''+row[0]+'\',\''+row[12]+'\',\''+row[1]+'\',\''+row[10]+'\')">查看详情</span></a></div>';


                        }
                        else if(row[10]==20){
                            val = '<a class="powerButton 174"><span class="list"  onclick="detail(\'会员\',\'reviewFailure.html\',\''+row[0]+'\',\''+row[12]+'\',\''+row[1]+'\',\''+row[10]+'\')">查看详情</span></a></div>';




                        }
                        else if(row[10]==30){
                            val = '<a class="powerButton 174"><span class="list"  onclick="detail(\'会员\',\'reviewFailure.html\',\''+row[0]+'\',\''+row[12]+'\',\''+row[1]+'\',\''+row[10]+'\')">查看详情</span></a></div>';




                        }
                        return val;
                    },
                    "targets":12
                }


            ]
        });
//权限控制函数
        power()
    };
}


//查看详情
function detail(title,url,member_id,id,loginacounts,status) {
    sessionStorage.setItem("member_id",member_id);
    sessionStorage.setItem("id",id);
    sessionStorage.setItem("loginacounts",loginacounts);
    if(status==20){
        sessionStorage.setItem("status","true")
    }else {
        sessionStorage.setItem("status","")
    }

    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

//弹框跳转
var examstatus= sessionStorage.getItem("examstatus")
console.log(examstatus)
if(examstatus==10){
    $('#exam_status').val(examstatus)
    searchLists()
}